package fun.xingwangzhe.tryfishport.mixin.client;

import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import fun.xingwangzhe.tryfishport.client.TryFishportUI;

@Mixin(MultiplayerScreen.class)
public class MultiplayerScreenMixin extends Screen {
    protected MultiplayerScreenMixin(Text title) {
        super(title);
    }

    @Inject(at = @At("TAIL"), method = "init()V")
   private void onInit(CallbackInfo ci) {
       // 在服务器列表界面左下角添加自定义按钮
       this.addDrawableChild(ButtonWidget
           .builder(Text.translatable("tryfishport.button.tryfishport"), button -> {
               System.out.println(Text.translatable("tryfishport.log.button.tryfishport.clicked").getString());
               // 打开TryFishportUI界面
               net.minecraft.client.MinecraftClient.getInstance().setScreen(new TryFishportUI(this));
           })
           .dimensions(5, this.height - 25, 100, 20)
           .build());
   }
}